package com.hmall.search.web;

import com.hmall.common.dto.PageDTO;
import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.pojo.RequestParams;
import com.hmall.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
public class SearchController {
    @Autowired
    private SearchService searchService;

    /**
     * 搜索栏自动补全功能
     * @param str 输入的信息
     * @return
     */
    @GetMapping("/suggestion")
    public List<String> getSuggestion(@RequestParam("str") String str){

        return searchService.getSuggestion(str);
    }


    /**
     * 过滤项聚合/search/filters
     * @param params
     * @return
     */
    @PostMapping("filters")
    public Map<String,List<String>> getFilters(@RequestBody RequestParams params){
        return searchService.getFilters(params);
    }

    /**
     * 商品查询
     * @param params
     * @return
     */
    @PostMapping("list")
    public PageDTO<ItemDoc> search(@RequestBody RequestParams params){
        return searchService.search(params);
    }
}
